﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HR.Appointments.DataLayer;
using HR.Appointments.Service.ValueObjects;

namespace HR.Appointments.Service.DisplayLists
{
    /// <summary>
    /// An object to better display time in gridview
    /// </summary>
    public class TimeList
    {
        #region Private Members
        private TimeUnit _time;
        private WorkstationEntity _workstation;
        private CompanyEntity _company;
        #endregion

        #region Constructors
        /// <summary>
        /// Wrapp the timeunit into an timelist object
        /// </summary>
        /// <param name="time">A valid time unit</param>
        /// <param name="workstation">A valid workstaion entity or null</param>
        /// <param name="company">A valid company entity or null</param>
        public TimeList(TimeUnit time, WorkstationEntity workstation, CompanyEntity company)
        {
            _time = time;
            _workstation = workstation;
            _company = company;
        }
        #endregion

        #region Public Properties
        /// <summary>
        /// Time to be displayed
        /// </summary>
        public string Time
        {
            get { return _time.ToString(); }
        }

        /// <summary>
        /// Time unit object
        /// </summary>
        public TimeUnit TimeUnit
        {
            get { return _time; }
        }

        /// <summary>
        /// Workstation name
        /// </summary>
        public string WorkstationName
        {
            get 
            {
                if (_workstation != null)
                    return _workstation.Name.ToString();
                else
                    return string.Empty;
            }
        }

        /// <summary>
        /// Company name 
        /// </summary>
        public string CompanyName
        {
            get
            {
                if (_company != null)
                    return _company.Name.ToString();
                else
                    return string.Empty;
            }
        }
        #endregion

        #region Override Methods
        /// <summary>
        /// Determines whether the specified Object is equal to the current Object.
        /// </summary>
        /// <param name="obj">The Object to compare with the current Object.</param>
        /// <returns>true if the specified Object is equal to the current Object; otherwise, false.</returns>
        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType()) return false;
            TimeList eql = (TimeList)obj;
            return (eql.Time == Time);
        }

        /// <summary>
        /// Serves as a hash function for a this type.
        /// </summary>
        /// <returns>A hash code for the current Object.</returns>
        public override int GetHashCode()
        {
            return _time.GetHashCode();
        }

        /// <summary>
        /// Returns a String that represents the current Object.
        /// </summary>
        /// <returns>A String that represents the current Object.</returns>
        public override string ToString()
        {
            return WorkstationName + " " + _time.ToString();
        }
        #endregion
    }
}
